from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-17 14:02:19.206826
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 17, Apr, 2022
Time: 14:02:25
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.9920
Nobs: 629.000 HQIC: -49.3809
Log likelihood: 7665.36 FPE: 2.79825e-22
AIC: -49.6279 Det(Omega_mle): 2.42792e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.331818 0.063090 5.259 0.000
L1.Burgenland 0.106003 0.039739 2.668 0.008
L1.Kärnten -0.110643 0.020819 -5.315 0.000
L1.Niederösterreich 0.194848 0.083050 2.346 0.019
L1.Oberösterreich 0.119846 0.081882 1.464 0.143
L1.Salzburg 0.259432 0.042153 6.155 0.000
L1.Steiermark 0.044314 0.055493 0.799 0.425
L1.Tirol 0.104939 0.044917 2.336 0.019
L1.Vorarlberg -0.065314 0.039626 -1.648 0.099
L1.Wien 0.021083 0.072718 0.290 0.772
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.044851 0.135080 0.332 0.740
L1.Burgenland -0.036480 0.085083 -0.429 0.668
L1.Kärnten 0.041636 0.044574 0.934 0.350
L1.Niederösterreich -0.199813 0.177815 -1.124 0.261
L1.Oberösterreich 0.454706 0.175314 2.594 0.009
L1.Salzburg 0.283683 0.090251 3.143 0.002
L1.Steiermark 0.110313 0.118813 0.928 0.353
L1.Tirol 0.307253 0.096170 3.195 0.001
L1.Vorarlberg 0.026899 0.084841 0.317 0.751
L1.Wien -0.024614 0.155694 -0.158 0.874
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190933 0.032250 5.920 0.000
L1.Burgenland 0.088975 0.020313 4.380 0.000
L1.Kärnten -0.007468 0.010642 -0.702 0.483
L1.Niederösterreich 0.244312 0.042453 5.755 0.000
L1.Oberösterreich 0.160180 0.041856 3.827 0.000
L1.Salzburg 0.040246 0.021548 1.868 0.062
L1.Steiermark 0.027324 0.028367 0.963 0.335
L1.Tirol 0.083520 0.022961 3.638 0.000
L1.Vorarlberg 0.054725 0.020256 2.702 0.007
L1.Wien 0.118946 0.037172 3.200 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109448 0.032289 3.390 0.001
L1.Burgenland 0.042876 0.020338 2.108 0.035
L1.Kärnten -0.013296 0.010655 -1.248 0.212
L1.Niederösterreich 0.173778 0.042504 4.088 0.000
L1.Oberösterreich 0.333713 0.041907 7.963 0.000
L1.Salzburg 0.101143 0.021574 4.688 0.000
L1.Steiermark 0.112891 0.028401 3.975 0.000
L1.Tirol 0.091425 0.022988 3.977 0.000
L1.Vorarlberg 0.061009 0.020280 3.008 0.003
L1.Wien -0.013662 0.037217 -0.367 0.714
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.109503 0.060482 1.810 0.070
L1.Burgenland -0.045551 0.038096 -1.196 0.232
L1.Kärnten -0.045795 0.019958 -2.295 0.022
L1.Niederösterreich 0.137607 0.079617 1.728 0.084
L1.Oberösterreich 0.163775 0.078498 2.086 0.037
L1.Salzburg 0.283594 0.040410 7.018 0.000
L1.Steiermark 0.059734 0.053199 1.123 0.262
L1.Tirol 0.160585 0.043061 3.729 0.000
L1.Vorarlberg 0.098664 0.037988 2.597 0.009
L1.Wien 0.080102 0.069712 1.149 0.251
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054328 0.047334 1.148 0.251
L1.Burgenland 0.026368 0.029814 0.884 0.376
L1.Kärnten 0.052925 0.015619 3.388 0.001
L1.Niederösterreich 0.196547 0.062309 3.154 0.002
L1.Oberösterreich 0.331399 0.061432 5.395 0.000
L1.Salzburg 0.037269 0.031625 1.178 0.239
L1.Steiermark 0.011441 0.041634 0.275 0.783
L1.Tirol 0.121614 0.033699 3.609 0.000
L1.Vorarlberg 0.066927 0.029729 2.251 0.024
L1.Wien 0.102073 0.054557 1.871 0.061
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.168218 0.056894 2.957 0.003
L1.Burgenland 0.005487 0.035835 0.153 0.878
L1.Kärnten -0.065758 0.018774 -3.503 0.000
L1.Niederösterreich -0.102262 0.074893 -1.365 0.172
L1.Oberösterreich 0.206633 0.073840 2.798 0.005
L1.Salzburg 0.055116 0.038012 1.450 0.147
L1.Steiermark 0.245482 0.050042 4.906 0.000
L1.Tirol 0.501400 0.040505 12.379 0.000
L1.Vorarlberg 0.063918 0.035734 1.789 0.074
L1.Wien -0.075763 0.065576 -1.155 0.248
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.146259 0.063103 2.318 0.020
L1.Burgenland -0.001353 0.039746 -0.034 0.973
L1.Kärnten 0.062523 0.020823 3.003 0.003
L1.Niederösterreich 0.169526 0.083066 2.041 0.041
L1.Oberösterreich -0.053265 0.081898 -0.650 0.515
L1.Salzburg 0.207494 0.042161 4.921 0.000
L1.Steiermark 0.139908 0.055504 2.521 0.012
L1.Tirol 0.058050 0.044926 1.292 0.196
L1.Vorarlberg 0.148812 0.039633 3.755 0.000
L1.Wien 0.124365 0.072733 1.710 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377889 0.037223 10.152 0.000
L1.Burgenland -0.003035 0.023445 -0.129 0.897
L1.Kärnten -0.020665 0.012283 -1.682 0.092
L1.Niederösterreich 0.206624 0.048999 4.217 0.000
L1.Oberösterreich 0.230362 0.048310 4.768 0.000
L1.Salzburg 0.038065 0.024870 1.531 0.126
L1.Steiermark -0.013179 0.032740 -0.403 0.687
L1.Tirol 0.089187 0.026501 3.365 0.001
L1.Vorarlberg 0.053537 0.023379 2.290 0.022
L1.Wien 0.043577 0.042903 1.016 0.310
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036699 0.110934 0.173241 0.139814 0.101666 0.081598 0.037213 0.210810
Kärnten 0.036699 1.000000 -0.024652 0.131908 0.050826 0.086779 0.443763 -0.065708 0.090058
Niederösterreich 0.110934 -0.024652 1.000000 0.316570 0.124852 0.276858 0.069728 0.155388 0.292615
Oberösterreich 0.173241 0.131908 0.316570 1.000000 0.216960 0.299309 0.167896 0.139467 0.241257
Salzburg 0.139814 0.050826 0.124852 0.216960 1.000000 0.126097 0.093702 0.107433 0.127129
Steiermark 0.101666 0.086779 0.276858 0.299309 0.126097 1.000000 0.136213 0.110356 0.039390
Tirol 0.081598 0.443763 0.069728 0.167896 0.093702 0.136213 1.000000 0.065946 0.152225
Vorarlberg 0.037213 -0.065708 0.155388 0.139467 0.107433 0.110356 0.065946 1.000000 -0.002843
Wien 0.210810 0.090058 0.292615 0.241257 0.127129 0.039390 0.152225 -0.002843 1.000000